package com.example.day_blog.service;

import com.example.day_blog.mapper.BlogInfoMapper;
import com.example.day_blog.mapper.UserInfoMapper;
import com.example.day_blog.model.BlogInfo;
import com.example.day_blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author starsea
 * @date 2024-01-18 18:20
 */
@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    public UserInfo queryByName(String name)
    {
        return userInfoMapper.queryByName(name);
    }
    public UserInfo queryById(Integer id)
    {
        return userInfoMapper.queryById(id);
    }
    public UserInfo getAuthorInfo(Integer id)
    {
        //通过博客id获取博客信息
        BlogInfo blogInfo=blogInfoMapper.queryByBlogId(id);
        //通过作者id查询作者信息
        if(blogInfo==null)
        {
            return null;
        }
        Integer userId=blogInfo.getUserId();
        UserInfo userInfo=userInfoMapper.queryById(userId);
        return userInfo;
    }
    public Integer insertUser(UserInfo userInfo)
    {
        return userInfoMapper.InsertUser(userInfo);
    }
    //显示用户所写文章数
    public Integer articals(Integer userId)
    {
        return blogInfoMapper.sumBlogNumber(userId);
    }
}
